<?php
    class LoginView{
    	
		//Konstanter 
		const RIGHT = "right";
		const WRONG = "wrong";
		const NOT = "not";
		    	
		//postvariables
		private static $name = "name";
		private static $username = "username";
		private static $password = "password";
	    private static $logIn = "logIn";
		private static $logOut = "logOut";
		private static $remember = "remember";
    	
		// Function for loginform
		public function DoLoginBox (){
				
			$u = "";
			$p = "";
			
			if (isset($_COOKIE[self::$username])) {	
					$u = $_COOKIE[self::$username];
					$p = $_COOKIE[self::$password];
					
			}
				
			return"
				   <form method='post' class='loginForm'> 
				   	Name: <input type='text' name=".self::$name." value='$u' /><br />
					Password: <input type='password' name=".self::$password." value='$p'  />
					<input type='submit' value='Log in' name=".self::$logIn." class='loginBotton'  ></input>
					<input type='checkbox' name='remember' value=".self::$remember." class='box'  /> Remember me<br />
			       </form>";
		}
		
		public function DoLogoutBox(){
				
			return"<form method='post' class='loginForm'> 
				     <input type='submit' value='Log out' name=".self::$logOut."></input>
			       </form>";
		}
		
		public function GetUserName(){
			
			 if(isset( $_POST[self::$name])){
			 	return $_POST[self::$name];	 	
			 }
			 else{
			 	return null;
			 }	
		}
		
		public function GetPassword(){
				
			if(isset( $_POST[self::$password])){
		 	return $_POST[self::$password];	 	
			}
			else{
			 	return null;
			}
		}
		
		
		public function TriedToLogin(){
				
			if(isset($_POST[self::$logIn])){
		 		return true;	 	
			}
			else{
			 	return false;
			}	
		}
		
		public function TriedToLogOut(){
				
			if(isset($_POST[self::$logOut])){
		 		return true;	 	
			}
			else{
			 	return false;
			}	
		}
		
		public function rememberMe (){
			if (isset($_POST[self::$remember])) {
				return true;
			}
			else
			{
				return false;
			}
		}
		
		public function setCookies (){
			setcookie(self::$username,$this->GetUserName(),time() + (86400 * 7));
			setcookie(self::$password,$this->GetPassword(),time() + (86400 * 7));
		}
		
		public function displayMessage($status){
			$class = "wrong";
				switch ($status) {
					case 'wrong':
						$message ="Wrong username or password";
						break;
					
					case 'not':
						$message = "You are logged out";
						break;
					
					case 'right':
						$message = "You are now logged in";
						$class = "right";
						break;
					
					default:
						
						break;
				}
			
			return "<div class='message'><p class=".$class.">".$message."</p></div>";
			
			
		}
    } 
?>